package com.huilan.etl.util;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

/**
 * 常量类
 * @author ghy
 * @date 2018-12-29 17:26
 **/
public class ConstantsUtil {

    /**
     * 获取类属性名称及属性值得Map集合
     * @param clazz 常量静态类
     * @return Map集合
     */
    public static Map<String,String> getFieldMap(Class clazz)  {

        Map<String,String> fieldMap = new HashMap<String,String>();
        Field[] declaredFields = clazz.getDeclaredFields();
        for(Field field:declaredFields){
            field.setAccessible(true);
            String fieldName = field.getName();
            String fieldValue = null;
            try {
                fieldValue = (String)field.get(clazz);
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
            fieldMap.put(fieldName,fieldValue);
        }
        return fieldMap;
    }

}
